/**
 * 
 */
package com.worksmap.core.action.system;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.worksmap.core.action.BaseController;
import com.worksmap.core.constant.LoginConstant;
import com.worksmap.core.entity.User;
import com.worksmap.core.service.LoginService;

/**
 * 系统管理员的登录
 * @author jack
 * 2013.9.11
 */
@Controller
@RequestMapping("/system/login")
public class SystemLoginController extends BaseController {
	
	@Autowired
	LoginService loginService;
	
	@RequestMapping(value = "", method = RequestMethod.GET)
	public String login(HttpServletRequest request){
		logger.info("跳转到系统管理员登录页面");
		return "system/login";
	}
	
	@RequestMapping(value = "check", method = RequestMethod.POST)
	public String checkLogin(User user, HttpServletRequest request, HttpServletResponse response){
		logger.info("登录信息：" + user.getUserName() + " 密码:" + user.getPassWord());
		int loginResult = loginService.sysAdminLogin(user, request, response);
		if(LoginConstant.USER_LOGIN_SUCCESS != loginResult){
			request.setAttribute("loginStatus", LoginConstant.ERROR_MAP.get(loginResult));
			return "system/login";
		}
		return "system/index";
	}

}
